package com.happy3w.game.guess_num;

import java.util.Random;

public class NumGenerator {
    private Random random = new Random();

    public int gen() {
        int[] candidateNums = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9 , 0};
        int candidateLength = candidateNums.length;

        int num = 0;
        for (int i = 0; i < 4; i++) {
            int bound = i == 0 ? candidateLength - 1: candidateLength;
            int index = random.nextInt(bound);

            num = num * 10 +  candidateNums[index];
            candidateLength--;
            candidateNums[index] = candidateNums[candidateLength];
        }
        return num;
    }
}
